;;; init-basic.el -*- lexical-binding: t; -*-

;; Personal infomation
(setq user-full-name canary\user-name)
(setq user-mail-address canary\mail-address)

;; UTF-8 as the default coding system
(when (fboundp 'set-charset-priority)
  (set-charset-priority 'unicode))
(prefer-coding-system 'utf-8)
(setq locale-coding-system 'utf-8)
(unless *sys-is-windows*
  (setq selection-coding-system 'utf-8))

;; Ensure all Canary's essentail local directories exist.
(dolist (dir (list canary-local-dir
                   canary-cache-dir
                   canary-etc-dir))
  (unless (file-directory-p dir)
    (make-directory dir)))

(fset 'yes-or-no-p 'y-or-n-p)           ; use y/n instead of yes/no
(setq debug-on-error canary\debug-mode)
(setq mouse-yank-at-point t)            ; yank at cursor, not mouse point
(setq x-select-enable-clipboard t)      ; support yank from emacs and other apps
(setq inhibit-compacting-font-caches t) ; cache fonts
(setq ffap-machine-p-known 'reject)     ; don't ping things that look like domain names
(setq ring-bell-function #'ignore)      ; no beeping

;; Be quiet at startup; don't load or display anything unnecessary
(setq inhibit-default-init t)           ; don't load the `default' library
(setq initial-major-mode 'text-mode)
(setq initial-scratch-message nil)

;; History & backup
(setq auto-save-default nil)
(setq create-lockfiles nil)
(setq history-length 1000)
(setq make-backup-files nil)            ; don't create backup~ files
(setq enable-recursive-minibuffers t)   ; allow invoke commands even minibuffer is active

;; Save the last place of point in a file you previously visited
(use-package saveplace
  :hook (after-init . save-place-mode)
  :init
  (setq save-place-file (expand-file-name "places" canary-cache-dir)))

(use-package savehist
  :hook (after-init . savehist-mode)
  :init
  (setq savehist-file (expand-file-name "savehist" canary-cache-dir))
  (setq savehist-additional-variables '(mark-ring
                                        global-mark-ring
                                        search-ring
                                        regexp-search-ring
                                        extended-command-history
                                        evil-jumps-history))
  (setq savehist-autosave-interval 300))

(use-package recentf
  :hook (after-init . recentf-mode)
  :init
  (setq recentf-save-file (expand-file-name "recentf" canary-cache-dir))
  (setq recentf-max-saved-items 1000)
  (setq recentf-exclude '((expand-file-name package-user-dir)
                          ".cache"
                          ".cask"
                          "bookmarks"
                          "cache"
                          "ido.*"
                          "persp-confs"
                          "recentf"
                          "undo-tree-hist"
                          "url"
                          "COMMIT_EDITMSG\\'")))

(provide 'init-basic)
